from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-01 14:03:10.065089
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 01, Jan, 2023
Time: 14:03:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3430
Nobs: 888.000 HQIC: -51.6428
Log likelihood: 11761.6 FPE: 3.09920e-23
AIC: -51.8283 Det(Omega_mle): 2.80207e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296654 0.049246 6.024 0.000
L1.Burgenland 0.105919 0.033823 3.132 0.002
L1.Kärnten -0.106344 0.018164 -5.855 0.000
L1.Niederösterreich 0.213404 0.070933 3.009 0.003
L1.Oberösterreich 0.081488 0.067060 1.215 0.224
L1.Salzburg 0.250396 0.035924 6.970 0.000
L1.Steiermark 0.029708 0.047148 0.630 0.529
L1.Tirol 0.126519 0.038336 3.300 0.001
L1.Vorarlberg -0.060128 0.032934 -1.826 0.068
L1.Wien 0.066542 0.059836 1.112 0.266
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062490 0.101066 0.618 0.536
L1.Burgenland -0.009328 0.069413 -0.134 0.893
L1.Kärnten 0.049300 0.037276 1.323 0.186
L1.Niederösterreich -0.170826 0.145573 -1.173 0.241
L1.Oberösterreich 0.360555 0.137625 2.620 0.009
L1.Salzburg 0.285761 0.073726 3.876 0.000
L1.Steiermark 0.107682 0.096759 1.113 0.266
L1.Tirol 0.319406 0.078675 4.060 0.000
L1.Vorarlberg 0.025256 0.067589 0.374 0.709
L1.Wien -0.024447 0.122800 -0.199 0.842
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200332 0.025617 7.820 0.000
L1.Burgenland 0.090836 0.017594 5.163 0.000
L1.Kärnten -0.008798 0.009448 -0.931 0.352
L1.Niederösterreich 0.267040 0.036898 7.237 0.000
L1.Oberösterreich 0.109763 0.034883 3.147 0.002
L1.Salzburg 0.053764 0.018687 2.877 0.004
L1.Steiermark 0.015838 0.024525 0.646 0.518
L1.Tirol 0.101362 0.019941 5.083 0.000
L1.Vorarlberg 0.057690 0.017132 3.367 0.001
L1.Wien 0.113099 0.031126 3.634 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104800 0.026248 3.993 0.000
L1.Burgenland 0.048302 0.018027 2.679 0.007
L1.Kärnten -0.016308 0.009681 -1.684 0.092
L1.Niederösterreich 0.197873 0.037807 5.234 0.000
L1.Oberösterreich 0.275855 0.035743 7.718 0.000
L1.Salzburg 0.117803 0.019147 6.152 0.000
L1.Steiermark 0.100582 0.025130 4.003 0.000
L1.Tirol 0.125092 0.020433 6.122 0.000
L1.Vorarlberg 0.070597 0.017554 4.022 0.000
L1.Wien -0.025472 0.031893 -0.799 0.424
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131989 0.047292 2.791 0.005
L1.Burgenland -0.053316 0.032480 -1.641 0.101
L1.Kärnten -0.036243 0.017443 -2.078 0.038
L1.Niederösterreich 0.166302 0.068118 2.441 0.015
L1.Oberösterreich 0.130496 0.064398 2.026 0.043
L1.Salzburg 0.290565 0.034498 8.423 0.000
L1.Steiermark 0.034041 0.045276 0.752 0.452
L1.Tirol 0.159675 0.036814 4.337 0.000
L1.Vorarlberg 0.109570 0.031627 3.464 0.001
L1.Wien 0.068415 0.057462 1.191 0.234
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064169 0.037562 1.708 0.088
L1.Burgenland 0.038433 0.025798 1.490 0.136
L1.Kärnten 0.050163 0.013854 3.621 0.000
L1.Niederösterreich 0.226245 0.054103 4.182 0.000
L1.Oberösterreich 0.265909 0.051149 5.199 0.000
L1.Salzburg 0.060752 0.027400 2.217 0.027
L1.Steiermark -0.007062 0.035961 -0.196 0.844
L1.Tirol 0.157203 0.029240 5.376 0.000
L1.Vorarlberg 0.068602 0.025120 2.731 0.006
L1.Wien 0.076311 0.045639 1.672 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188537 0.045137 4.177 0.000
L1.Burgenland 0.017637 0.031001 0.569 0.569
L1.Kärnten -0.058673 0.016648 -3.524 0.000
L1.Niederösterreich -0.096120 0.065015 -1.478 0.139
L1.Oberösterreich 0.177197 0.061465 2.883 0.004
L1.Salzburg 0.061373 0.032927 1.864 0.062
L1.Steiermark 0.226233 0.043214 5.235 0.000
L1.Tirol 0.483663 0.035137 13.765 0.000
L1.Vorarlberg 0.052160 0.030186 1.728 0.084
L1.Wien -0.050288 0.054844 -0.917 0.359
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153300 0.051054 3.003 0.003
L1.Burgenland -0.000927 0.035064 -0.026 0.979
L1.Kärnten 0.067141 0.018830 3.566 0.000
L1.Niederösterreich 0.201861 0.073537 2.745 0.006
L1.Oberösterreich -0.068847 0.069521 -0.990 0.322
L1.Salzburg 0.220763 0.037243 5.928 0.000
L1.Steiermark 0.108143 0.048878 2.212 0.027
L1.Tirol 0.084008 0.039743 2.114 0.035
L1.Vorarlberg 0.127610 0.034143 3.738 0.000
L1.Wien 0.108201 0.062033 1.744 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356862 0.030253 11.796 0.000
L1.Burgenland 0.008307 0.020778 0.400 0.689
L1.Kärnten -0.025377 0.011158 -2.274 0.023
L1.Niederösterreich 0.229279 0.043576 5.262 0.000
L1.Oberösterreich 0.150423 0.041197 3.651 0.000
L1.Salzburg 0.052829 0.022069 2.394 0.017
L1.Steiermark -0.016524 0.028964 -0.570 0.568
L1.Tirol 0.121625 0.023551 5.164 0.000
L1.Vorarlberg 0.073576 0.020232 3.637 0.000
L1.Wien 0.050413 0.036759 1.371 0.170
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039101 0.164467 0.183904 0.171303 0.147059 0.130709 0.068115 0.220836
Kärnten 0.039101 1.000000 0.002598 0.132624 0.027484 0.099136 0.430717 -0.048588 0.101612
Niederösterreich 0.164467 0.002598 1.000000 0.350103 0.174317 0.318016 0.135018 0.193558 0.343537
Oberösterreich 0.183904 0.132624 0.350103 1.000000 0.237276 0.344714 0.183989 0.180732 0.274703
Salzburg 0.171303 0.027484 0.174317 0.237276 1.000000 0.157291 0.141152 0.154192 0.142697
Steiermark 0.147059 0.099136 0.318016 0.344714 0.157291 1.000000 0.165974 0.149409 0.098522
Tirol 0.130709 0.430717 0.135018 0.183989 0.141152 0.165974 1.000000 0.125304 0.165215
Vorarlberg 0.068115 -0.048588 0.193558 0.180732 0.154192 0.149409 0.125304 1.000000 0.021324
Wien 0.220836 0.101612 0.343537 0.274703 0.142697 0.098522 0.165215 0.021324 1.000000